Ari Lamstein (@AriLamstein)
San Francisco R-Ladies Meetup, May 2015
Introduce yourself to your neighbor
Today we will use R to understand the demographics of the
Then we will
library(choroplethr)
data(df_pop_state)
?df_pop_state
head(df_pop_state)
region value
1 alabama 4777326
2 alaska 711139
3 arizona 6410979
4 arkansas 2916372
5 california 37325068
6 colorado 5042853
Exercise: What is the population of your home state? Tell your neighbor.
df_pop_state[df_pop_state$region == "new york", ]
region value
33 new york 19398125
boxplot(df_pop_state$value)
Exercise: Draw one interpretation from this plot
state_choropleth(df_pop_state)
Exercise: Draw one interpretation from this map
state_choropleth(df_pop_state, num_colors = 2)
Exercise: Draw one interpretation from this map
state_choropleth(df_pop_state, num_colors = 1)
Exercise: Draw one interpretation from this map
data(df_state_demographics)
?df_state_demographics
colnames(df_state_demographics)
[1] "region" "total_population" "percent_white"
[4] "percent_black" "percent_asian" "percent_hispanic"
[7] "per_capita_income" "median_rent" "median_age"
Exercise: Make a choropleth map of one statistic above. Share it with your neighbor.
df_state_demographics$value = df_state_demographics$percent_white
state_choropleth(df_state_demographics, num_colors=2)
library(choroplethr)
data(df_pop_county)
head(df_pop_county)
region value
1 1001 54590
2 1003 183226
3 1005 27469
4 1007 22769
5 1009 57466
6 1011 10779
Exercise: Use google to find the FIPS code of the county you are from. Share it with your neighbor.
Exercise: What is the population of the county you are from? Share it with your neighbor.
Write down your county FIPS code. We'll be using it later.
# 36059 is the FIPS code for Nassau County, NY
df_pop_county[df_pop_county$region == 36059, ]
region value
1858 36059 1338712
boxplot(df_pop_county$value)
Exercise: Draw one interpretation from this boxplot
county_choropleth(df_pop_county)
Exercise: Draw one interpretation from this map
county_choropleth(df_pop_county, num_colors=1)
Exercise: Draw one interpretation from this map
county_choropleth(df_pop_county, state_zoom="california", num_colors=4)
Exercise: Draw one interpretation from this map
data(df_county_demographics)
colnames(df_county_demographics)
[1] "region" "total_population" "percent_white"
[4] "percent_black" "percent_asian" "percent_hispanic"
[7] "per_capita_income" "median_rent" "median_age"
Exercise: Make a map of some demographic of the counties of your home state. Share it with your neighbor.
df_county_demographics$value = df_county_demographics$percent_asian
county_choropleth(df_county_demographics, num_colors=1, state_zoom="new york")
Post Office maintains ZIP Codes
Census maintains Zip Code Tabulated Areas (ZCTA)
ZIP Codes are difficult to analyze:
library(choroplethrZip)
data(df_pop_zip)
head(df_pop_zip)
region value
132 01001 17380
133 01002 28718
134 01003 11286
135 01005 5120
136 01007 14593
137 01008 1160
Exercise: What is the population of the zip you are from? Tell your neighbor.
df_pop_zip[df_pop_zip$region == "11021", ]
region value
2811 11021 17449
boxplot(df_pop_zip$value)
Exercise: Draw one interpretation from this boxplot
zip_choropleth(df_pop_zip, state_zoom="new york")
Exercise: Draw one inference from this map
# 36059 is the FIPS code for Nassau County, NY
zip_choropleth(df_pop_zip, county_zoom=36059)
Exercise: Draw one inference from this map
Create a choropleth map showing the population of the zip codes in your home state. Share it with your neighbor.
Create a choropleth map showing the population of the zip codes in your home county. Share it with your neighbor.
data(df_zip_demographics)
colnames(df_zip_demographics)
[1] "region" "total_population" "percent_white"
[4] "percent_black" "percent_asian" "percent_hispanic"
[7] "per_capita_income" "median_rent" "median_age"
Exercise: Make a map of some demographic of the ZIPs in your home state. Share it with your neighbor.
df_zip_demographics$value = df_zip_demographics$per_capita
zip_choropleth(df_zip_demographics, state_zoom="new york")
Exercise: Draw one inference from this map
Exercise: Make a map of some demographic of the ZIPs in your home county. Share it with your neighbor.
df_zip_demographics$value = df_zip_demographics$per_capita
zip_choropleth(df_zip_demographics, county_zoom=36059, num_colors=1)
Exercise: Draw one inference from this map
library(acs)
# api.key.install("<key>")
?get_state_demographics library(choroplethr)
df_2010 = get_state_demographics(2010, 5)
df_2010[df_2010$region == "new york",
"total_population"]
[1] 19229752
Exercise: What was the population of your home state according to the 2010 5-year ACS?
# 6075 is the county FIPS code for San Francisco
zip_choropleth_acs("B19067", county_zoom=6075, num_colors=3)
Please provide feedback!
Need a software engineer or data analyst?
Keep in touch!